<?php echo $header; ?>

 
<?php if ($success) { ?>
<div class="success"><?php echo $success; ?></div>
<?php } ?>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script>
<style type="text/css">

#l-map{height:500px;width:100%;border:2px solid #bcbcbc;display:block;}

</style>
<script type="text/javascript" src="catalog/view/javascript/cookie.js"></script>
<div style="width:100%;height:1024px;border:1px solid">
<div id='number_street_xstreet' style="width:100%;" >
<button onclick='lookup_location(); return false;'>找到我!</button>   
<form action='<?php echo $action; ?>' method='POST' id='form_1'>
            <table>
                <!-- For English, we want the number before the street, for Chinese, after -->

                    <tr>
                        <td><label for='street'>路名</label></td>
                        <td><input id='street' type='text'></input></td>
                        <td>例如: 辽源路</td>
                    </tr>               
                    <tr>
                        <td><label for='number'>门牌号</label></td>
                        <td><input id='number' type='text'></input></td>
                        <td>例如: 257号</td>
                    </tr>
                

           
            </table>

       <a onclick='lookup_location()' >找到我</a>
      <a onclick="$('#form_1').submit()">
	 </form>
	   
    </div>
	<div id="l-map"></div>
	</div>
	<script type="text/javascript">


	function RndNum(n){
		var rnd="";
		for(var i=0;i<n;i++)
		{
			rnd+=Math.floor(Math.random()*10);
		}
		
		return rnd;
	}
	
	function lookup_location() {
 
			var position;
			
			var key = <?php echo $key;?>;
            var number = document.getElementById('number').value;
            var street = document.getElementById('street').value;
            

			var citys = '青岛';
			var address = street+number;
			
			var map = new BMap.Map("l-map");
			var point = new BMap.Point(36.071398,120.897445);
			map.centerAndZoom(point,12);
			var marker = new BMap.Marker(point) 
			map.addOverlay(marker);
			
			
			// 创建地址解析器实例
			var myGeo = new BMap.Geocoder();
			// 将地址解析结果显示在地图上,并调整地图视野
			myGeo.getPoint(address, function(point){
			  if (point) {
				map.centerAndZoom(point, 16);
				marker.setPosition(point); 
				map.addOverlay(marker);
				
			    position = marker.getPosition();
				alert(position.lng+','+position.lat);
				
				$.ajax({
				    type: "GET",
				    url: "index.php?route=stores/selectaddress/setposition",
				    data: "positionlng="+position.lng+"&positionlat="+position.lat+"&key="+key+"",
				    success: function(msg){
					 alert( "Data Saved: " + msg );
				    }
				});
				
			  }else{
				alert(您输入的地址不正确);
			  }
			}, citys);
			if(marker){
				marker.enableDragging();    //可拖拽
					marker.addEventListener("dragend", function(e){
					position = e.point;
					alert(position.lng+','+position.lat);
					$.ajax({
						type: "GET",
						url: "index.php?route=stores/selectaddress/setposition",
						data: "positionlng="+position.lng+"&positionlat="+position.lat+"&key="+key+"",
						success: function(msg){
						 alert( "Data Saved: " + msg );
						}
					});
					
				});
			
			}
			
    }
	function successforcode(msg){
		alert(msg['status']);
	}
</script>



	<?php echo $footer; ?>
